package com.zoe.onelink.redis.checker;

import com.zoe.onelink.plugin.check.AbstractEnvironmentChecker;
import com.zoe.onelink.plugin.check.model.PropertyCheckResult;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2023</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2023-02-01
 */
@RequiredArgsConstructor
public class OnelinkRedisEnvironmentChecker extends AbstractEnvironmentChecker {

    private final RedisProperties redisProperties;

    @Override
    protected List<PropertyCheckResult<?>> doCheck() {
        List<PropertyCheckResult<?>> propertyCheckResults = new ArrayList<>();
        Duration timeout = this.redisProperties.getTimeout();
        if (timeout != null && timeout.toMillis() <= 0) {
            PropertyCheckResult<Object> checkResult = new PropertyCheckResult<>()
                    .setPropKey("spring.redis.timeout")
                    .setPropValue(timeout)
                    .setLevel(PropertyCheckResult.Level.DANGER)
                    .setMessage("Redis超时时间小于或等于0,请将其设置到一个大于0的合理范围");
            propertyCheckResults.add(checkResult);
        }
        return propertyCheckResults;
    }

}
